<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>EnvSub</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
</head>
<body>

<h1>EnvSub</h1>

<p>Sets a <a href="../Variables.htm">variable</a> to itself minus the given value (can also compare <a href="FileSetTime.htm#YYYYMMDD">date-time</a> values). Synonymous with: <code>Var -= Value</code>.</p>

<pre class="Syntax">EnvSub, Var, Value [, TimeUnits]
Var -= Value [, TimeUnits]
Var--</pre>
<h3>Parameters</h3>
<dl>

  <dt>Var</dt>
  <dd><p>The name of the <a href="../Variables.htm">variable</a> upon which to operate.</p></dd>

  <dt>Value</dt>
  <dd><p>Any integer, floating point number, or <a href="../Variables.htm#Expressions">expression</a> (expressions are not supported when <em>TimeUnits</em> is present).</p></dd>

  <dt>TimeUnits</dt>
  <dd><p>If present, this parameter directs the command to  subtract <em>Value</em> from <em>Var</em> as though both of them are date-time stamps in the <a href="FileSetTime.htm#YYYYMMDD">YYYYMMDDHH24MISS</a> format. <em>TimeUnits</em> can be either Seconds, Minutes, Hours, or Days (or just the first letter of each of these). If <em>Value</em> is blank, the current time will be used in its place. Similarly, if <em>Var</em> is an empty variable, the current time will be used in its place.</p>
      <p>The result is always rounded <em>down</em> to the nearest integer. For example, if the actual difference between two timestamps is 1.999 days, it will be reported as 1 day. If higher precision is needed, specify Seconds for <em>TimeUnits</em> and divide the result by 60.0, 3600.0, or 86400.0.</p>
      <p>If either <em>Var</em> or <em>Value</em> is an invalid timestamp or contains a year prior to 1601, <em>Var</em> will be made blank to indicate the problem.</p>
      <p>The built-in variable <strong>A_Now</strong> contains the current local time in <a href="FileSetTime.htm#YYYYMMDD">YYYYMMDDHH24MISS</a> format.</p>
      <p>To precisely determine the elapsed time between two events, use the <a href="../Variables.htm#TickCount">A_TickCount method</a> because it provides millisecond precision.</p>
      <p>To add or subtract a certain number of seconds, minutes, hours, or days from a timestamp, use <a href="EnvAdd.htm">EnvAdd</a> (subtraction is achieved by adding a negative number).<br>
      </p></dd>

</dl>

<h3>Remarks</h3>
<p>This command is equivalent to the shorthand style: <code>Var -= Value</code>.</p>
<p>Variables can be increased or decreased by 1 by using <code>Var++</code>, <code>Var--</code>, <code>++Var</code>, or <code>--Var</code>.</p>
<p>If either <em>Var</em> or <em>Value</em> is blank or does not start with a number, it is considered to be 0 for the purpose of the calculation (except when used <em>internally</em> in an expression and except when using the <em>TimeUnits</em> parameter).</p>
<p>If either <em>Var</em> or <em>Value</em> contains a decimal point, the end result will be a floating point number in the format set by <a href="SetFormat.htm">SetFormat</a>.</p>
<h3>Related</h3>
<p><a href="EnvAdd.htm">EnvAdd</a>, <a href="EnvMult.htm">EnvMult</a>, <a href="EnvDiv.htm">EnvDiv</a>, <a href="SetFormat.htm">SetFormat</a>, <a href="../Variables.htm#Expressions">Expressions</a>, <a href="IfIs.htm">If var is [not] type</a>, <a href="SetEnv.htm">SetEnv</a>, <a href="FileGetTime.htm">FileGetTime</a></p>
<h3>Example</h3>
<pre class="NoIndent">EnvSub, MyCount, 2
MyCount -= 2  <em>; Equivalent to above</em>

var1 = 20050126
var2 = 20040126
EnvSub, var1, %var2%, days
MsgBox, %var1%  <em>; The answer will be 366 since 2004 is a leap year.</em></pre>

</body>
</html>
